﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.WmsManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.WmsManagement.MaterialStoreVMs
{
    public partial class MaterialStoreListVM : BasePagedListVM<MaterialStore_View, MaterialStoreSearcher>
    {
        
        protected override IEnumerable<IGridColumn<MaterialStore_View>> InitGridHeader()
        {
            return new List<GridColumn<MaterialStore_View>>{
                
                this.MakeGridHeader(x => x.MaterialStore_Material).SetTitle(@Localizer["Page.物料"].Value),
                this.MakeGridHeader(x => x.MaterialStore_MinStore).SetTitle(@Localizer["Page.最低库存"].Value),
                this.MakeGridHeader(x => x.MaterialStore_StoreQty).SetTitle(@Localizer["Page.当前在库"].Value),
                this.MakeGridHeader(x => x.MaterialStore_MaxStore).SetTitle(@Localizer["Page.最高库存"].Value),
                this.MakeGridHeader(x => x.MaterialStore_Expiration).SetTitle(@Localizer["Page.保质期"].Value),
                this.MakeGridHeader(x => x.MaterialStore_LastInBatch).SetTitle(@Localizer["Page.最近入库批次"].Value),
                this.MakeGridHeader(x => x.MaterialStore_LastInStoreTime).SetTitle(@Localizer["Page.最近入库时间"].Value),
                this.MakeGridHeader(x => x.MaterialStore_LastOutStoreTime).SetTitle(@Localizer["Page.最近出库时间"].Value),
                this.MakeGridHeader(x => x.MaterialStore_Pos).SetTitle(@Localizer["Page.存放位置"].Value),
                this.MakeGridHeader(x => x.MaterialStore_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.MaterialStore_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.MaterialStore_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.MaterialStore_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<MaterialStore_View> GetSearchQuery()
        {
            var query = DC.Set<MaterialStore>()
                
                .CheckEqual(Searcher.MaterialId, x=>x.MaterialId)
                .CheckEqual(Searcher.MinStore, x=>x.MinStore)
                .CheckEqual(Searcher.StoreQty, x=>x.StoreQty)
                .CheckEqual(Searcher.MaxStore, x=>x.MaxStore)
                .CheckEqual(Searcher.Expiration, x=>x.Expiration)
                .CheckContain(Searcher.LastInBatch, x=>x.LastInBatch)
                .CheckBetween(Searcher.LastInStoreTime?.GetStartTime(), Searcher.LastInStoreTime?.GetEndTime(), x => x.LastInStoreTime, includeMax: false)
                .CheckEqual(Searcher.LastOutStoreTime, x=>x.LastOutStoreTime)
                .CheckContain(Searcher.Pos, x=>x.Pos)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new MaterialStore_View
                {
				    ID = x.ID,
                    
                    MaterialStore_Material = x.Material.TenantCode,
                    MaterialStore_MinStore = x.MinStore,
                    MaterialStore_StoreQty = x.StoreQty,
                    MaterialStore_MaxStore = x.MaxStore,
                    MaterialStore_Expiration = x.Expiration,
                    MaterialStore_LastInBatch = x.LastInBatch,
                    MaterialStore_LastInStoreTime = x.LastInStoreTime,
                    MaterialStore_LastOutStoreTime = x.LastOutStoreTime,
                    MaterialStore_Pos = x.Pos,
                    MaterialStore_CreateTime = x.CreateTime,
                    MaterialStore_UpdateTime = x.UpdateTime,
                    MaterialStore_CreateBy = x.CreateBy,
                    MaterialStore_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class MaterialStore_View: MaterialStore
    {
        
        public string MaterialStore_Material { get; set; }
        public decimal? MaterialStore_MinStore { get; set; }
        public decimal? MaterialStore_StoreQty { get; set; }
        public decimal? MaterialStore_MaxStore { get; set; }
        public decimal? MaterialStore_Expiration { get; set; }
        public string MaterialStore_LastInBatch { get; set; }
        public DateTime? MaterialStore_LastInStoreTime { get; set; }
        public decimal? MaterialStore_LastOutStoreTime { get; set; }
        public string MaterialStore_Pos { get; set; }
        public DateTime? MaterialStore_CreateTime { get; set; }
        public DateTime? MaterialStore_UpdateTime { get; set; }
        public string MaterialStore_CreateBy { get; set; }
        public string MaterialStore_UpdateBy { get; set; }

    }

}